package multithread;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

import com.example.concurrent.CyclicBarrier.CyclicBarrierRunnable;

public class Teee implements Comparable{
	private static final Exchanger<String> exgr = new Exchanger<String>();
	private static ExecutorService threadPool = Executors.newFixedThreadPool(2);

	public static void main(String[] args) {
//		ConcurrentNavigableMap ssss= new ConcurrentSkipListMap();
//		FutureTask ss;
//		
//		CyclicBarrier barrier2 = new CyclicBarrier(2, null);
//
//		CyclicBarrierRunnable barrierRunnable1 =
//		        new CyclicBarrierRunnable(null, null);
//		
//		System.out.println(Integer.MAX_VALUE);
////		SingleThreadScheduledExecutor
////		Executors.newScheduledThreadPool(corePoolSize)
////		Executors.newSingleThreadScheduledExecutor()
//		
//		threadPool.execute(new Runnable() {
//			@Override
//			public void run() {
//				try {
//					String A = "银行流水A"; // A录入银行流水数据
//					String att=exgr.exchange(A);
//					System.out.println("1-"+att);
//				} catch (InterruptedException e) {
//				}
//			}
//		});
//		threadPool.execute(new Runnable() {
//			@Override
//			public void run() {
//				try {
//					String B = "银行流水B"; // B录入银行流水数据
//					String A = exgr.exchange("Bcd");
//					System.out.println("2-"+A);
//					System.out.println("A和B数据是否一致：" + A.equals(B) + "，A录入的是：" + A + "，B录入是：" + B);
//				} catch (InterruptedException e) {
//				}
//			}
//		});
//		threadPool.shutdown();
		int a=10 ;
		long b=10L ; 
		double c=10.0;
		System.out.println(a==b);//true
		System.out.println(a==c);//true
		
		//==内存地址，equals内容 
		String sss1="abce";
		String sss2="abce"	;
		String sss3=new String("abce")	;
		String sss4=new String("abce")	;
		System.out.println(sss1.equals(sss2));
		System.out.println(sss4.equals(sss3));
		System.out.println(sss1==sss2);
		System.out.println(sss1==sss3);
		System.out.println(sss4==sss3);
		//Constructor<AAA> constructor = AAA.class.getInstance();

		System.out.println("---------------");
		try {
			//只加载不初始化static块没有执行
			Class ccc= Class.forName("multithread.AAA",true,AAA.class.getClassLoader());
			System.out.println(AAA.class);
			System.out.println(ccc);
			AAA ccc11=(AAA) ccc.newInstance();//非静态块，构造
			
			ObjectOutputStream out1 = new ObjectOutputStream(new FileOutputStream("sss.bin"));
			out1.writeObject(ccc11);
			out1.close();
			
			ObjectInputStream in1 = new ObjectInputStream(new FileInputStream("sss.bin"));
			AAA ccc12=(AAA) in1.readObject();
			System.out.println(ccc12);
			
			System.out.println("---------------------1-");
			Constructor[] cons = ccc.getConstructors();
			System.out.println(Arrays.toString(cons));
			Constructor con = ccc.getConstructor(String.class);
			con.newInstance("ddddd");
			
			Method[] mes = ccc.getMethods();
			System.out.println(Arrays.toString(mes));

			Field[] fies = ccc.getFields();//公共属性
			System.out.println(Arrays.toString(fies));

			Field[] fdies = ccc.getDeclaredFields();
			System.out.println(Arrays.toString(fdies));

			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("---------------");

		//需要补充的是：Class.forName("完整类名").newInstance();的用法相当于直接new();
		AAA ccc2 = new AAA();
		//System.out.println(ccc2.getClass());

		
		ArrayList arr1 = new ArrayList<>();
		arr1.add(1);
		arr1.add(2);
		arr1.add(3);
		/*for (Object object : arr1) {
			arr1.remove(object);//错误
		}*/
		System.out.println(arr1.size());
		Iterator it = arr1.iterator(); 	
		while(it.hasNext()){
			Object p=it.next();
			//arr1.remove(p);
			it.remove();
		}
		System.out.println(arr1.size());

		 int[] arrays = new int[]{1,2,3,4,5,6,7,8,9,10,1,2,3,4,5};
        Collection<Integer> set = new HashSet<Integer>();
        int counter = 0;
        for(int temp :arrays){
            if(set.add(temp)){
                counter++;
            }else{
                System.out.println("The date "+temp+" has already been existent,discard it.");
            }
        }
        System.out.println("counter=> "+counter);
        System.out.println("set.size()=> "+set.size());
	
        int[] arrays2 = new int[]{ 1,2,3,4,5,6,7,8,9,10,1,2,3,4,5};
		List  listss2 =Arrays.asList(arrays2);
        CopyOnWriteArrayList listtt = new CopyOnWriteArrayList(listss2);
        for(Object x:listtt){
        	listtt.remove(x);
        }
        System.out.println("set2.size()=> "+listtt.size());

	        
		LinkedList ll1;
		HashSet ha1;
		TreeMap tm1;
		TreeSet ts1;
		AbstractMap am1;
		//ListIterator lt1;
		CopyOnWriteArraySet coa1;
		CopyOnWriteArrayList col1;
		
		Collections collss;
		
	}

	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		return 0;
	}

}
